/**
 * Copyright 2014,Peak Tai 台俊峰(taijunfeng_it@sina.com).
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * 		http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.cenluan.common;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.ehcache.CacheKit;
import com.jfinal.plugin.ehcache.IDataLoader;

/**
 * 项目配置文件，主要是一些帐号的配置，如小米和QQ的开发者帐号。<br>
 * 把配置文件放数据库确实会增加程序的复杂性，降低性能，之所以这样做是因为项目是开源的，又不想想在代码里爆露帐号停息。
 * 
 * @author peak
 * 
 */
public class Profiles extends Model<Profiles> {

	private static final long serialVersionUID = 1L;

	public static final String CACHE_NAME = "profiles";

	/**
	 * 获取配置
	 * 
	 * @return
	 */
	public static Profiles find() {
		return CacheKit.get(CACHE_NAME, "xxx", new IDataLoader() {

			public Object load() {
				return new Profiles().findFirst("select * from t_profiles");
			}
		});
	}

	public static String getOssAccessKeyId() {
		return find().getStr("ossAccessKeyId");
	}

	public static String getOssAccessKeySecret() {
		return find().getStr("ossAccessKeySecret");
	}

	public static String getOssServer() {
		return find().getStr("ossServer");
	}

	public static String getOssImageBucket() {
		return find().getStr("ossImageBucket");
	}

	public static String getOssImageDomain() {
		return find().getStr("ossImageDomain");
	}

	public static String getMiAppId() {
		return find().getStr("miAppId");
	}

	public static String getMiAppKey() {
		return find().getStr("miAppKey");
	}
	public static String getMiAppSecret() {
		return find().getStr("miAppSecret");
	}
	public static String getQqAppId() {
		return find().getStr("qqAppId");
	}

	public static String getQqAppKey() {
		return find().getStr("qqAppKey");
	}

	@Override
	public boolean update() {
		CacheKit.removeAll(CACHE_NAME);
		return super.update();
	}

}
